<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>生命周期</title>
</head>

<body>
    <div id="app">
        <button @click="destroyVM">destroy</button>
        <p v-show="isShow">这是文本</p>
    </div>
    <script src="https://cdn.bootcss.com/vue/2.5.16/vue.js"></script>
    <script>
        const vm = new Vue({
            el: '#app',
            data: {
                isShow: true
            },
            //初始化阶段
            beforeCreate() {
                console.log('beforeCreate()');
            },
            created() {
                console.log('created()');
            },
            beforeMount() {
                console.log('beforeMount()');
            },
            mounted() { //初始化显示之后立即调用（一次）
                this.intervalId = setInterval(() => {
                    console.log('-----------');
                    this.isShow = !this.isShow;
                }, 1000)
                console.log('mouted()');
            },
            //更新阶段
            beforeUpdate() {
                console.log('beforeUpdate()');
            },
            updated() {
                console.log('updated()');
            },
            //销毁阶段
            beforeDestroy() { //销毁之前调用（一次）
                clearInterval(this.intervalId);
                console.log('beforeDestroy()');
            },
            destroyed() {
                console.log('destroyed()');
            },
            methods: {
                destroyVM() {
                    this.$destroy()
                }
            }
        })
    </script>
</body>

</html>